package org.huangrui.juc.source.cf;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @Author hr
 * @Create 2024-04-01 14:11
 */
public class    T11_CompletableFutureCombine {
    public static void main(String[] args) {
        CompletableFuture<Integer> supply = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+": 启动");
            try { TimeUnit.MILLISECONDS.sleep(10);} catch (InterruptedException e) {e.printStackTrace();}
            return 10;
        });
        CompletableFuture<Integer> supplyAsync = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+": 启动");
            try { TimeUnit.MILLISECONDS.sleep(10);} catch (InterruptedException e) {e.printStackTrace();}
            return 20;
        });
        CompletableFuture<Integer> combine = supply.thenCombine(supplyAsync, Integer::sum);
        System.out.println(combine.join());
    }
}
